package com.rongc.client.freight.base.view.fragment;

import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.rongc.client.core.utils.ActivityUtils;
import com.rongc.client.core.utils.StringUtils;
import com.rongc.client.freight.ApiUrl;
import com.rongc.client.freight.R;
import com.rongc.client.freight.UniApplication;
import com.rongc.client.freight.base.BaseFragment;
import com.rongc.client.freight.base.view.widget.ProgressWebView;
import com.rongc.client.freight.business.mine.view.activity.HdActivity;

import butterknife.Bind;

/**
 * Created by Bruce on 2016/11/24.
 */
public class HDFragment extends BaseFragment {
    @Bind(R.id.webview)
    ProgressWebView webview;
    String url;

    public static HDFragment getInstance(){
        /*if(fragment == null) fragment = new HomeFragment(orderType);
        return fragment;*/
        HDFragment fragment = new HDFragment();
        Bundle bdl = new Bundle();
//        bdl.putString("orderType", orderType);
        fragment.setArguments(bdl);
        return fragment;
    }

    @Override
    public void initData() {
    }

    @Override
    public void initListener() {

    }


    @Override
    public void initView() {
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webview.getSettings().setSupportMultipleWindows(true);
//		webview.setWebViewClient(new WebViewClient());
        webview.setWebChromeClient(new WebChromeClient());
        webview.setWebViewClient(new WebViewClient(){

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if(true){
                    Bundle bundle = new Bundle();
                    bundle.putString("url",url);
                    ActivityUtils.startActivity(getActivity(), HdActivity.class,bundle);
                    return true;
                }
                return false;
            }

        });
        if(StringUtils.isNotEmpty(url)){
            webview.loadUrl(url);
        }else{
            url = ApiUrl.getDefaultHost()+"active.html?userid="+ UniApplication.getInstance().getUserInfo().getUserId();
            webview.loadUrl(url);
        }
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_hd;
    }
}
